package user.zc.config.user.config;


import user.zc.config.MapConfig;
import user.zc.config.ValueType;
import user.zc.config.value.Key;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

/**
 * @author zhouchuang
 * @date 2023/8/9 17:54
 */
public abstract class UserConfig<T extends Key> extends MapConfig<T> {
    protected static final String EXT = ".conf";
    public UserConfig(ValueType type) {
        super(type);
    }

    @Override
    public File getFile(String fileName){
        File file =  new File(System.getProperty("user.home")+File.separator + FOLD+File.separator+fileName+File.separator+getClass().getSimpleName()+EXT);
        if(!file.getParentFile().exists()){
            file.getParentFile().mkdirs();
        }
        return file;
    }

    @Override
    protected BufferedReader getConfBufferedReader(String fileName)throws Exception{
        File file =  getFile(fileName);
        return new BufferedReader(new FileReader(file));
    }

    @Override
    public void delete(String fileName) throws Exception {
        File file = getFile(fileName);
        file.delete();
    }
}
